package com.hualude.roadsign.repository;

import com.hualude.roadsign.dto.*;
import com.hualude.roadsign.model.RoadLineEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

/**
 * Created by pjn on 2017/8/14.
 */
public interface RoadLineRepository extends CrudRepository<RoadLineEntity, Long> {

    /**
     * @Description: 标线详情2Fault
     * @Author: pan-jianan
     * @Date: 2017/8/14 19:58
     */
    @Query(value = "select new com.hualude.roadsign.dto.LineFaultDto(rl.roadLineId,rl.coordinateId,rl.roadLineOrgId," +
            "rl.roadLineMainOrgId,rl.roadLineProvince,rl.roadLineCity,rl.roadLineArea,rl.roadLineRoadName,rl.roadLineStartRoad," +
            "rl.roadLineEndRoad,rl.roadLineType,rl.roadLineGraphic,rl.roadLinePhoto,rl.roadLineInstallTime," +
            "rl.roadLineInstallOrg,rl.roadLinePeriod, rl.roadLineServiceLife, rl.roadLineCreatorId,rl.roadLineMileage) " +
            "from RoadLineEntity rl where rl.roadLineId=?1")
    public LineFaultDto getRoadLineInfo2Fault(Integer roadLineId) throws Exception;

    /**
     * @Description: 标线故障modal datatable
     * @Author: pan-jianan
     * @Date: 2017/8/14 20:22
     */
    public List<DTLineFaultDto> getRoadLineFaultReport4DT(DTRequestDto dtRequestDto, Integer actorId, Integer orgId, String roadName, String startRoad, String endRoad) throws Exception;

    /**
     * @Description: 获取第一个路名
     * @Author: pan-jianan
     * @Date: 2017/8/14 20:59
     */
    public List<String> getRoadURoadName(String roadName, Integer actorId, Integer orgId) throws Exception;

    /**
     * @Description: 根据第一个获取第二个路名
     * @Author: pan-jianan
     * @Date: 2017/8/14 20:59
     */
    public List<String> getSectionUStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception;

    /**
     * @Description: 获取标线数据用于DT展示
     * @author xu_jiaHui
     * @date 2017/8/17 11:39
     */
    public List<RoadLineDto> getRoadLine4DT(DTRequestDto dtRequestDto,
                                            String actorIds,
                                            Integer orgId,
                                            Boolean audit,
                                            String startRoad,
                                            String endRoad,
                                            String roadName) throws Exception;

    /**
     * @Description: 获取标线数量用于DT展示
     * @author xu_jiaHui
     * @date 2017/8/17 11:47
     */
    public Integer getRoadLine4DTCount(DTRequestDto dtRequestDto, String actorIds, Integer orgId, Boolean audit, String startRoad, String endRoad, String roadName) throws Exception;

    /**
     * @Description: 删除标线
     * @author xu_jiaHui
     * @date 2017/8/17 13:00
     */
    @Modifying
    @Query(value = "delete from RoadLineEntity where roadLineId = ?1")
    public Integer deleteRoadLine(Integer roadLineId) throws Exception;

    /**
     * @Description: 审核标线
     * @author xu_jiaHui
     * @date 2017/8/17 13:01
     */
    @Modifying
    @Query(value = "update RoadLineEntity set roadLineIsComplete = 1 where roadLineId = ?1")
    public Integer auditRoadLine(Integer roadLineId) throws Exception;

    /**
     * @Description: 获取起始路名
     * @author xu_jiaHui
     * @date 2017/8/17 13:01
     */
    public List<String> getStartRoadByRoadName(String roadName, String actorIds, Integer orgId) throws Exception;

    /**
     * @Description: 获取结束路名
     * @author xu_jiaHui
     * @date 2017/8/17 13:05
     */
    public List<String> getEndRoadByStartRoad(String coverRoadName, String startRoad, String actorIds, Integer orgId) throws Exception;


    /**
     * @Description: 更新标线信息
     * @author xu_jiaHui
     * @date 2017/8/18 14:39
     */
    @Modifying
    @Query(value = "update RoadLineEntity set projectNumber=?2,roadLineProvince=?3,roadLineCity=?4,roadLineArea=?5," +
            "roadLineRoadName=?6,roadLineStartRoad=?7,roadLineEndRoad=?8,roadLineType=?9,roadLineGraphic=?10," +
            "roadLinePhoto=?11,roadLineInstallTime=?12,roadLineInstallOrg=?13,roadLinePeriod=?14,roadLineServiceLife=?15," +
            "roadLineRemark=?16,roadLineCreatorId=?17,roadLineModifierId=?18,roadLineOrgId=?19,roadLineMainOrgId=?20," +
            "roadLineIsComplete=0,roadLineMileage=?21 where roadLineId=?1")
    public Integer updateRoadLine(Integer roadLineId,
                                  String projectNumber,
                                  String roadLineProvince,
                                  String roadLineCity,
                                  String roadLineArea,
                                  String roadLineRoadName,
                                  String roadLineStartRoad,
                                  String roadLineEndRoad,
                                  Integer roadLineType,
                                  Integer roadLineGraphic,
                                  String roadLinePhoto,
                                  String roadLineInstallTime,
                                  String roadLineInstallOrg,
                                  Integer roadLinePeriod,
                                  Integer roadLineServiceLife,
                                  String roadLineRemark,
                                  Integer roadLineCreatorId,
                                  Integer roadLineModifierId,
                                  Integer roadLineOrgId,
                                  Integer roadLineMainOrgId,
                                  String roadLineMileage) throws Exception;

    /**
     * @Description: 获取坐标集用于地图展示
     * @author xu_jiaHui
     * @date 2017/8/19 13:13
     */
    public List<RoadLineDto> getRoadLineCoordinates4Map(Integer orgId, Integer orgType, Integer actorId) throws Exception;





    @Query(value = "select new com.hualude.roadsign.dto.MapInfoDto(r.roadLineId,r.roadLinePhoto,r.projectNumber," +
            "r.roadLineProvince,r.roadLineCity,r.roadLineArea,r.roadLineRoadName,r.roadLineStartRoad," +
            "r.roadLineEndRoad,r.roadLineType,r.roadLineGraphic,r.roadLineInstallTime,r.roadLineInstallOrg,r.roadLinePeriod," +
            "r.roadLineServiceLife,r.roadLineRemark,u.userName,o1.orgName,o2.orgName) from " +
            "RoadLineEntity r,OrgEntity o1,OrgEntity o2,UserEntity u where o1.orgId=r.roadLineOrgId and " +
            "o2.orgId=r.roadLineMainOrgId and r.roadLineCreatorId=u.userId and r.roadLineId=?1 ")
    public MapInfoDto getRoadLineInfoById(Integer elementId) throws Exception;


    /**
     * @Description: 获取坐标以及图片
     * @Author: jiang-weirong
     * @Date: 2017/8/25 19:59
     */
    public List<LineFaultDto> getRoadLineCoordinates4AppMap(Integer orgId, Integer orgType, Integer actorId) throws Exception;


    /**
     * @Description: 根据OrgId, actorId获取城市4App
     * @author xu_jiaHui
     * @date 2017/10/9 15:42
     */
    public List<String> getCity4RoadLine(String actorIds, Integer orgId, Integer mCount, Integer mSize) throws Exception;

    /**
     * @Description: 根据city获取路口4App
     * @author xu_jiaHui
     * @date 2017/10/9 16:17
     */
    public List<String> getStartRoadByCity(String city, String actorIds, Integer orgId, Integer mCount, Integer mSize) throws Exception;

    /**
     * @Description: 通过城市 起始路名 获取结束路名4App
     * @author xu_jiaHui
     * @date 2017/10/9 16:21
     */
    public List<String> getSectionByStartRoad4App(String city, String roadName, String actorIds, Integer orgId, Integer mCount, Integer mSize) throws Exception;



    /**
     * @Description: 获取标线信息用于列表展示4App
     * @author Jiang_Zhengyu
     * @date 2017/10/13 17:27
     */
    public List<RoadLineDto> getRoadLine4APP(String actorIds, Integer orgId, Integer mCount, Integer mSize, String city, String startRoad, String endRoad, String roadName) throws Exception;

    /**
     * @Description: 通过城市获取路名
     * @author Jiang_Zhengyu
     * @date 2017/10/14 23:02
     */
    public List<String> getRoadName4RoadLineByCity(String actorIds, Integer orgId, String city, Integer mCount, Integer mSize) throws Exception;

    /**
     * @Description: 根据城市路名起始路名 获取结束路名
     * @author Jiang_Zhengyu
     * @date 2017/10/14 23:03
     */
    public List<String> getEndRoadByStartRoad4App(String city, String roadName, String startRoad, String actorIds, Integer orgId, Integer mCount, Integer mSize);

    /**
     * @Description: 根据城市 路名 获取起始路名
     * @author Jiang_Zhengyu
     * @date 2017/10/14 23:03
     */
    public List<String> getStartRoadByRoadName4App(String city, String roadName, String actorIds, Integer orgId, Integer mCount, Integer mSize) throws Exception;

    /**
     * @Description: 通过Id获取标线信息
     * @author Jiang_Zhengyu
     * @date 2017/10/13 19:48
     */
    public RoadLineDto getRoadLineById(Integer roadLineId) throws Exception;

    /**
     * @Description: app地图
     * @Author: shao-yikun
     * @Date: 2017/11/23 上午9:39
     */
    public List<RoadLineDto> getRoadLine4Map4App(Integer orgId,
                                                 String actorIds,
                                                 double neLongitude,
                                                 double neLatitude,
                                                 double swLongitude,
                                                 double swLatitude) throws Exception;

}


